package arch.dao.impl.statistics;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import arch.dao.statistics.ArchStatisticsDao;
import arch.domain.archive.Category;
import arch.domain.archive.Retention;
import arch.domain.statistics.ArchStatistics;
/**
 * 
 * @author <a mailto="wanglong635@126.com">Long</a>
 *
 */
@Repository("archStatisticsDao")
public class ArchStatisticsImpl implements ArchStatisticsDao {
	@Resource private JdbcTemplate jdbcTemplate; 
	
	@SuppressWarnings("unchecked")
	public List<ArchStatistics> findComplexList(String sql, Object... objects) {
		return this.jdbcTemplate.query(sql,objects,new RowMapper(){
			public Object mapRow(ResultSet rs, int i) throws SQLException {
				ArchStatistics arch = new ArchStatistics();
				
				Retention retention = new Retention();
				retention.setId(rs.getInt("RETENTION_ID"));
				arch.setRetention(retention);
				
				arch.setSecurity(rs.getString("security"));
				
				Category category = new Category();
				category.setId(rs.getInt("CATEGORY_ID"));
				arch.setCategory(category);
				
				arch.setCreatorDeptCode(rs.getString("CREATOR_ID"));
				arch.setCreatorDeptName(rs.getString("CREATOR_NAME"));
				arch.setFiles(rs.getInt("count"));
				return arch;
			}});
	}

	@SuppressWarnings("unchecked")
	public List<ArchStatistics> findSimpleList(String sql, Object... objects) {
		return this.jdbcTemplate.query(sql,objects,new RowMapper(){
			public Object mapRow(ResultSet rs, int i) throws SQLException {
				ArchStatistics arch = new ArchStatistics();
				arch.setYear(rs.getInt("Year"));
				
				Retention retention = new Retention();
				retention.setId(rs.getInt("RETENTION_ID"));
				arch.setRetention(retention);
				
				arch.setFiles(rs.getInt("Count"));
				arch.setPages(rs.getInt("Pages"));
				arch.setBoxes(rs.getInt("Boxes"));
				return arch;
			}});
	}

}
